package com.djakapm.swing.component.textarea;

import org.junit.*;
import junit.framework.JUnit4TestAdapter;

import javax.swing.*;
import java.awt.*;

import static org.junit.Assert.assertTrue;

public class SpecForTextAreaRowNumberPanel {
    public static junit.framework.Test suite() {
        return new JUnit4TestAdapter(SpecForTextAreaRowNumberPanel.class);
    }

    @Test
    public void can_add_line() {
       TextAreaLineNumberPanel talnp = new TextAreaLineNumberPanel();
       talnp.setLineNumber(3).addLineNumber();
       Component[] components = talnp.getComponents();
        assertTrue("Component count should be equal to 3",components.length == 3);
        assertTrue("Line count should be equal to 3",talnp.getLineNumber() == 3);
       for(int idx=0; idx<components.length; idx++){
           JLabel label = (JLabel) components[idx];
           assertTrue("All label is visible and display correct number",label.isVisible() && ((idx+1)+"").equals(label.getText()));
       }
    }

    @Test
    public void can_remove_line(){
        TextAreaLineNumberPanel talnp = new TextAreaLineNumberPanel();
        talnp.setLineNumber(5).addLineNumber();
        talnp.setLineNumber(3).removeLineNumber();
        Component[] components = talnp.getComponents();
        assertTrue("Component count should be equal to 3",components.length == 5);
        assertTrue("Line number should be equal to 3",talnp.getLineNumber() == 3);
        JLabel label = (JLabel) components[0];
        assertTrue("First label text should be equal to 1",label.isVisible() && "1".equals(label.getText()));
        label = (JLabel) components[1];
        assertTrue("Second label text should be equal to 2",label.isVisible() && "2".equals(label.getText()));

        label = (JLabel) components[2];
        assertTrue("Third label text should be equal 3",label.isVisible() && "3".equals(label.getText()));
        label = (JLabel) components[3];
        assertTrue("Fourth label text should be equal to empty string",label.isVisible() && "".equals(label.getText()));
        label = (JLabel) components[4];
        assertTrue("Fifth label text should be equal to empty string",label.isVisible() && "".equals(label.getText()));

    }
}